package com.sunny.ynhz.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sunny.ynhz.R;
import com.sunny.ynhz.bean.DailyBtnsBean;
import com.sunny.ynhz.event.ClickEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by luao on 2017/7/12.
 */

public class DailyBtnsAdapter extends BaseQuickAdapter<DailyBtnsBean, BaseViewHolder> {
    private Fragment mFragment;

    public DailyBtnsAdapter(@Nullable List<DailyBtnsBean> data, Fragment fragment) {
        super(R.layout.item_daily_btns, data);
        this.mFragment = fragment;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final DailyBtnsBean item) {
        helper.setImageResource(R.id.image, item.getResourceId());
        helper.setText(R.id.btns, item.getText());


        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.getText().equals("综合资讯")) {
                    EventBus.getDefault().post(new ClickEvent("zonghezixun"));
                } else if (item.getText().equals("河长巡河")) {
                    EventBus.getDefault().post(new ClickEvent("xunhe"));
                }
                if (item.getIntentClass() != null) {
                    if (item.getText().equals("新闻动态") || item.getText().equals("通知公告")
                            || item.getText().equals("清河行动") || item.getText().equals("他山之石")
                            || item.getText().equals("河长须知") || item.getText().equals("政策法规")
                            || item.getText().equals("红黑榜") || item.getText().equals("网箱养鱼") || item.getText().equals("河道采砂")) {
                        Intent intent = new Intent(mFragment.getContext(), item.getIntentClass());
                        intent.putExtra("title", item.getText());
                        String text = item.getText();
                        int id = 0;
                        String type = "";
                        if (text.equals("新闻动态")) {
                            id = 0;
                        } else if (text.equals("通知公告")) {
                            id = 12;
                        } else if (text.equals("清河行动")) {
                            id = 3;
                        } else if (text.equals("他山之石")) {
                            id = 2;
                        } else if (text.equals("河长须知")) {
                            id = 5;
                        } else if (text.equals("政策法规")) {
                            id = 1;
                        } else if (text.equals("网箱养鱼")) {
                            type = "1";
                        } else if (text.equals("河道采砂")) {
                            type = "2";

                        }
                        intent.putExtra("id", id);
                        intent.putExtra("type",type);
                        mFragment.startActivityForResult(intent, 200);
                    } else {
                        Intent intent = new Intent(mContext, item.getIntentClass());
                        intent.putExtra("title", item.getText());
                        mContext.startActivity(intent);
                    }

                }

            }
        });
    }
}
